from datetime import datetime, timedelta, time

from odoo import fields, models, _
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT


class ReportProductStockwizard(models.TransientModel):
    _name = 's.report.product.stock.wizard'
    _description = 'Product Stock Report wizard'

    start_date = fields.Date('Start Date', required=True)
    end_date = fields.Date('End Date', required=True)

    def action_download(self):
        start_date = min(self.start_date, self.end_date)
        end_date = max(self.start_date, self.end_date) + timedelta(days=1)

        return {
            'name': _('Product Stock Report'),
            'view_mode': 'tree',
            'res_model': 's.product.stock.report',
            'type': 'ir.actions.act_window',
            'context': {
                'start_date': start_date.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
                'end_date': end_date.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
            },
        }
